<?php
	require './config.php';

	// 1、链接数据库
	$link=mysqli_connect(HOST,USER,PWD,DB) or die("数据库链接失败");

	// 2、设置字符集
	mysqli_set_charset($link,CHAR);

	// 3、准备sql语句
	$sql="SELECT o.`id`, o.`name` AS oname, o.`pic`, o.`price`, o.`qty`, o.`tel`, o.`address` AS oadd, o.`dingdanhao` AS oding, f.`id`, f.`oid`, f.`shouhuo` AS fshou
  FROM `order` AS o,`orderinfo` AS f
  WHERE o.`id` = f.`oid`";
	// var_dump($sql);
	// exit;

	// 发送sql语句
	$res=mysqli_query($link,$sql);
	// var_dump($res);
	// exit;
    if ($res && mysqli_num_rows($res)>0) {
        $lis = array();
        while ($row = mysqli_fetch_assoc($res)) {
            $lis[] = $row;
        	// var_dump($lis);
        	// exit;
        }
    }else{
        return false;
    }

	mysqli_free_result($res);
    //8.关闭MYSQL连接
    mysqli_close($link);
	
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="renderer" content="webkit">
	<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
	<meta name="author" content="云淡然;http://ydr.me">
	<meta name="keywords" content="关键词1,关键词2">
	<meta name="description" content="描述语句">
	<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
	<link rel="apple-touch-icon" href="/favicon.png">
	<title>订单页面</title>
	<style>
		tr{
			text-align: center;
		}
		a{text-decoration: none;}
		.tj{margin-left: -720px;cursor: pointer;background: #00AEDB;border: 1px solid #00AEDB;border-radius: 5px;color: #fff;}
		table{margin-top: 10px;}
		.fahuo{cursor: pointer;background: #F78F1D;border: 1px solid #F78F1D;border-radius: 5px;width: 55px;height: 25px;color: #fff;}
		.shouhuo{cursor: pointer;background: #8CC63F;border: 1px solid #8CC63F;border-radius: 5px;width: 65px;height: 30px;color: #fff;}
		.xq{cursor: pointer;background: green;border: 1px solid green;border-radius: 5px;width: 65px;height: 30px;color: #fff;}
		.bj{cursor: pointer;background: blue;border: 1px solid blue;border-radius: 5px;width: 65px;height: 30px;color: #fff;}
		.sc{cursor: pointer;background: #f00;border: 1px solid #f00;border-radius: 5px;width: 65px;height: 30px;color: #fff;}
	</style>
</head>
<body>
	<center>
		<form action="">
			<caption><h1>订单列表页</h1></caption>
			<a class="tj" href="./add.php">订单添加</a>
			<table border="1" cellpadding="10" cellspacing="0" width="800">
				<tr>
					<th>订单号</th>
					<th>图片</th>
					<th>商品名</th>
					<th>价格</th>
					<th>数量</th>
					<th>状态</th>
					<th>操作</th>
				</tr>
				<?php if (empty($lis)): ?>
					<tr>
						<td colspan="7">暂无数据</td>
					</tr>
				<?php else: ?>
					<?php foreach ($lis as $key => $value): ?>
						<tr>
							<td><?php echo $value['oding'] ?></td>
							<td><img src="../imgs/<?php echo $value['pic'] ?>">
							</td>
							<td><?php echo $value['oname'] ?></td>
							<td><?php echo $value['price'] ?></td>
							<td><?php echo $value['qty'] ?></td>
							<th>
								<?php
									switch ($value['fshou']) {
										case 0:
											echo '<input class="fahuo" type="submit" value="未发货">';
											break;
										case 1:
											echo '<input class="fahuo" type="submit" value="已发货">';
											break;
										case 2:
											echo '<input class="fahuo" type="submit" value="已完成">';
											break;
									}
								?>
								
							</th>
							<td>
								<a href="./info.php">查看详情</a>
								<a href="./edit.php">编辑</a>
								<a href="./del.php">删除</a>
							</td>
						</tr>
					<?php endforeach ?>
				<?php endif ?>
			</table>
		</form>
	</center>
</body>
</html>